#！D:\MyWork\Program\python
# -*- coding: utf-8 -*-
import pymysql

def adjustcolumnsTableLabel():
    sql="select a.IndicatorID,a.Label from indicator_partner a left join  indicatorcategory_partner  b  on a.IndicatorCategoryID=b.IndicatorCategoryID where b.SourceId=181 and Label is not null"
    cur.execute(sql)
    datas=cur.fetchall()
    for data in datas:
        try:
            id=data[0]
            label=data[1]
            if label=='-1':
                label='18'
            elif '18' in label:
                label=label
            elif label=='0':
                label=label
            elif label==None:
                label='18'
            else:
                label=label+',18'
            print(str(id)+"|"+label)
            update='update indicator_partner set Label=%s where IndicatorID=%s'
            value=(label,id)
            cur.execute(update,value)
            conn.commit()
        except:
            print('失败id：'+str(id))


if __name__ == '__main__':
    try:
        conn = pymysql.Connect(host = '10.170.128.56',
                                port = 3306,
                                user = 'root',
                                passwd = '123456',
                                db = 'bd',
                                charset='utf8mb4')
        cur = conn.cursor()

        adjustcolumnsTableLabel()

    finally:
        cur.close()
        conn.close()